/**
 * @desc 表格公共组件
 * @props  {array} dataSource 表格数据源
 * @props  {array} columns    表头数据
 * @props  {bool} loading     是否显示loading
 */
import React from 'react'
import { Table } from 'antd';
import PropTypes from 'prop-types'
import TableColTools from './tools/ColTools'
import './style.less'
class TheTable extends React.Component {
    constructor(props) {
        super(props)
        this.state = {
            columnsCheck: []
        }
    }
    componentDidMount() {
        this.setState({
            columnsCheck: this.props.columns.map(item => {
                return item.dataIndex
            })
        })
    }
    checkTools(values) {
        console.log(values, '1123');
        this.setState({
            columnsCheck: values
        })
    }
    render() {
        const { dataSource, columns, loading, rowKey, scroll, pagination } = this.props;
        columns.map(v => {
            v.ellipsis = true
            v.align = 'center'
            v.width = v.width ? v.width : 140
            return v
        })
        return (
            <Table
                bordered
                expandable={{ defaultExpandAllRows: true }}
                loading={loading}
                pagination={false}
                {...this.props}
                scroll={scroll}
                dataSource={dataSource}
                columns={columns}
                rowKey={rowKey} />
        )
    }
}

TheTable.propTypes = {
    loading: PropTypes.bool,
    dataSource: PropTypes.array,
    columns: PropTypes.array,
    scroll: PropTypes.object,
    showTools: PropTypes.bool
}
TheTable.defaultProps = {
    loading: false,
    dataSource: [],
    columns: [],
    scroll: { x: 'max-content' },
    showTools: false
}
export default TheTable
